package shop.up.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import shop.up.common.result.Result;
import shop.up.model.product.BaseTrademark;
import shop.up.product.service.BaseTrademarkService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zzc
 * @date 2023/3/29 14:23
 */
@Api(tags = "品牌管理控制器")
@RestController
@RequestMapping("admin/product/baseTrademark")
public class BaseTrademarkController {

    @Resource
    private BaseTrademarkService baseTrademarkService;

    /**
     * 查询全部品牌
     * @return
     */
    @ApiOperation("获取品牌列表")
    @GetMapping("getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList() {
        List<BaseTrademark> trademarkList = baseTrademarkService.list(null);
        return Result.ok(trademarkList);
    }


    @ApiOperation("列表分页")
    @GetMapping("{page}/{limit}")
    public Result<IPage<BaseTrademark>> page(@PathVariable("page") Long page,
                                             @PathVariable("limit") Long limit) {
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage<BaseTrademark> pageResult = baseTrademarkService.page(baseTrademarkPage, null);
        return Result.ok(pageResult);
    }

    @ApiOperation("获取品牌")
    @GetMapping("get/{id}")
    public Result<BaseTrademark> get(@PathVariable("id") Long id) {
        BaseTrademark trademark = baseTrademarkService.getById(id);
        return Result.ok(trademark);
    }

    @ApiOperation("新增品牌")
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("修改品牌")
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable("id") Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }
}
